package com.itbaiyun.agent.rag;

import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Collections;
import java.util.List;

/**
 * 基于内存的向量存储
 */
@Configuration
public class VectoeStoreConfig {

    @Resource
    private DocumentLoader documentLoader;


    @Bean("myVectorStore")
    SimpleVectorStore myVectorStore(EmbeddingModel embeddingModel) {
        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(embeddingModel)
                .build();

        // 生成一个机器人产品说明书的文档
//        Document document =
//                new Document("产品说明书:产品名称：智能机器人\n" +
//                        "产品描述：智能机器人是一个智能设备，能够自动完成各种任务。\n" +
//                        "功能：\n" +
//                        "1. 自动导航：机器人能够自动导航到指定位置。\n" +
//                        "2. 自动抓取：机器人能够自动抓取物品。\n" +
//                        "3. 自动放置：机器人能够自动放置物品。\n");
        List<Document> documents = documentLoader.loadMarkdowns();
        simpleVectorStore.add(documents);
        return simpleVectorStore;
    }

}
